<template>
  <div class="goodsDetailsMessage info-content" @click="handleOpenGoodsMenuTab">
    <div class="info">
      <img class="img" :src="productImage" alt="" />
      <div class="price-box">
        <span class="name">{{ info.name }}</span>
        <span class="standard">{{ info.standard }}</span>
        <span class="price c26"> ￥{{ info.salePrice }}</span>
      </div>
    </div>
    <div class="number">{{$t('common.base.goodsNo')}}：{{ info.serialNumber }}</div>
  </div>
</template>

<script>
import { openAccurateTab } from '@src/util/platform';
import { PageRoutesTypeEnum } from '@model/enum/PageRoutesEnum';
import { getOssUrl } from '@src/util/assets'
const imgDefault = getOssUrl('/goodsDefault.png');
export default {
  name: 'goods-details-message',
  props: {
    item: {
      type: Object,
      default: () => ({}),
    },
  },
  data() {
    return {};
  },
  computed: {
    info() {
      return this.item?.messageContent?.customExts ?? {};
    },
    productImage(){
      return this.info.image || imgDefault
    }
  },
  methods: {
    handleOpenGoodsMenuTab() {
      let id = this.info?.id
      let name = this.info?.name ?? ''
      if (!id) return;

      let fromId = window.frameElement.getAttribute('id');

      openAccurateTab({
        type: PageRoutesTypeEnum.PageGoodsDetail,
        key: id,
        titleKey: ` - ${name}`,
        params: `id=${id}`,
        fromId,
      });
    },
  },
};
</script>

<style scoped lang='scss'>
.goodsDetailsMessage {
  width: 300px;
  background: #ffffff;
  box-sizing: border-box;
  cursor: pointer;
  .info {
    width: 100%;
    // height: 80px;
    background: #f5f5f5;
    border-radius: 8px;
    box-sizing: border-box;
    padding: 12px;
    display: flex;
    justify-content: center;
    font-size: 14px;
    margin-bottom: 10px;
    .img {
      width: 56px;
      height: 56px;
      border-radius: 8px;
    }
    .price-box {
      margin-left: 12px;
      width: 0;
      flex: 1;
      display: flex;
      flex-direction: column;
      .name {
        @include text-ellipsis;
        font-weight: bold;
      }
      .standard {
        font-size: 12px;
        color: #595959;
        margin-top: 2px;
      }
      .price {
        @include text-ellipsis;
        font-size: 12px;
        margin-top: 2px;
      }
    }
  }
  .number {
    font-size: 14px;
    line-height: 18px;
    color: #8c8c8c;
    line-height: 18px;
    @include text-ellipsis;
    margin-top: 2px;
  }
}
.c26 {
  color: #262626 !important;
}
</style>
